﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FOModels.PHighLight;
using DataAccess.PHighLight;
using System.Data;
namespace Bussiness.PHighLight
{

    public class PHighLightBLL
    {
        private PHighLightDAL dal;
        public PHighLightBLL()
        {
            dal = new PHighLightDAL();
        }
        public List<PHighLightModels> getTop5(int langid)
        {
            List<PHighLightModels> list = new List<PHighLightModels>();
            PHighLightModels fur;
            DataTable tb = dal.getTop5(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new PHighLightModels();
                    fur.PHighLightID = int.Parse(row[0].ToString());
                    fur.PHighLightName = row[7].ToString();
                    fur.PHighLightContent = row[8].ToString();
                    fur.Display = bool.Parse(row[2].ToString());
                    fur.OrderSort = int.Parse(row[3].ToString());
                    fur.Link = row[4].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public PHighLightModels getbyid(int PHighLightID, int langid)
        {

            PHighLightModels fur = new PHighLightModels();
            DataTable tb = dal.getbyid(PHighLightID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    
                    fur.PHighLightID = int.Parse(row[0].ToString());
                    fur.PHighLightName = row[7].ToString();
                    fur.PHighLightContent = row[8].ToString();
                    fur.Display = bool.Parse(row[2].ToString());
                    fur.OrderSort = int.Parse(row[3].ToString());
                    fur.Link = row[4].ToString();
                }
                return fur;
            }
            else
            {
                return null;
            }

        }
        public PHighLightModels gettop1()
        {
            PHighLightModels fur = new PHighLightModels();
            DataTable tb = dal.gettop1();
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur.PHighLightID = int.Parse(row[0].ToString());
                    fur.PHighLightName = row[1].ToString();
                    fur.Display = bool.Parse(row[2].ToString());
                    fur.OrderSort = int.Parse(row[3].ToString());
                    fur.Link = row[4].ToString();
                   
                }
                return fur;
            }
            else
            {
                return null;
            }
        }
        public List<PHighLightModels> getall(int langid)
        {
            List<PHighLightModels> list = new List<PHighLightModels>();
            PHighLightModels fur;
            DataTable tb = dal.getall(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new PHighLightModels();
                    fur.PHighLightID = int.Parse(row[0].ToString());
                    fur.Display = bool.Parse(row[2].ToString());
                    fur.OrderSort = int.Parse(row[3].ToString());
                    fur.Link = row[4].ToString();
                    fur.PHighLightName = row[7].ToString();
                    fur.PHighLightContent = row[8].ToString();
                    fur.FlagImage = row[12].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }

        public int UpdatePHighLight(PHighLightModels models, int langid)
        {
            if (dal.UpdatePHighLight(models) > 0 && dal.UpdatePHighLightLang(models, langid) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int InsertPHighLight(PHighLightModels models)
        {
            if (dal.InsertPHighLight(models) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int InsertPHighLightLang(PHighLightModels models, int langid)
        {
            if (dal.InsertPHighLightLang(models, langid) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int DeletePHighLight(int PHighLightID)
        {
            if (dal.DeletePHighLightLang(PHighLightID) > 0 && dal.DeletePHighLight(PHighLightID) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
    }
}
